package net.gzw1993.runmate.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;

import net.gzw1993.runmate.R;
import net.gzw1993.runmate.bean.Content;
import net.gzw1993.runmate.utils.MyBitmapUtilsHelper;

/**
 * Created by Administrator on 15-8-17.
 */
public class LineActivityAdapter extends SimpleBaseAdapter<Content> {
    private BitmapUtils bitmapUtils;

    public LineActivityAdapter(Context context) {
        super(context);
        MyBitmapUtilsHelper helper = MyBitmapUtilsHelper.getInstance();
        bitmapUtils = helper.getBitmapUtils();
    }


    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_online_activity_list, parent, false);
            ViewHolder holder = new ViewHolder();
            holder.headImage = (ImageView) convertView.findViewById(R.id.line_adapter_headImage);
            holder.headName = (TextView) convertView.findViewById(R.id.line_adapter_headName);
            holder.time = (TextView) convertView.findViewById(R.id.line_adapter_time);
            holder.joinNum = (TextView) convertView.findViewById(R.id.line_adapter_joinNum);
            convertView.setTag(holder);

        }
        ViewHolder holder = (ViewHolder) convertView.getTag();
        Content content = mList.get(position);
        if (content != null) {
            holder.headName.setText(content.getHeadName());
            holder.time.setText("8月16日 07:30");
            holder.joinNum.setText("参与人数:" + content.getJoinNum() + "");
            //动态设置图片的宽高
            ViewGroup.LayoutParams params = holder.headImage.getLayoutParams();
            params.width = mContext.getResources().getDisplayMetrics().widthPixels;
            params.height = (int) (params.width / 1.6);
            holder.headImage.setLayoutParams(params);
            bitmapUtils.display(holder.headImage, content.getHeadImage());
        }
        return convertView;
    }

    private static class ViewHolder {
        private ImageView headImage;
        private TextView headName;
        private TextView time;
        private TextView joinNum;
    }
}
